package com.sthz.facepay.mapper;

import com.sthz.facepay.model.Merchant;
import com.sthz.facepay.model.MerchantKey;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface MerchantMapper {
    @Delete({
        "delete from st_merchant",
        "where id = #{id,jdbcType=INTEGER}",
          "and name = #{name,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(MerchantKey key);

    @Insert({
        "insert into st_merchant (id, name, ",
        "contacts, phone, ",
        "data_time, pay_type, ",
        "business_abbreviation, shop_type, ",
        "address, service_phone, ",
        "weixin_appid, responsible_person, ",
        "contact, email, ",
        "cardholder, cash_bank, ",
        "bank_number, card_picture)",
        "values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{contacts,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, ",
        "#{data_time,jdbcType=DATE}, #{pay_type,jdbcType=TINYINT}, ",
        "#{business_abbreviation,jdbcType=VARCHAR}, #{shop_type,jdbcType=TINYINT}, ",
        "#{address,jdbcType=VARCHAR}, #{service_phone,jdbcType=VARCHAR}, ",
        "#{weixin_appid,jdbcType=VARCHAR}, #{responsible_person,jdbcType=VARCHAR}, ",
        "#{contact,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, ",
        "#{cardholder,jdbcType=VARCHAR}, #{cash_bank,jdbcType=VARCHAR}, ",
        "#{bank_number,jdbcType=VARCHAR}, #{card_picture,jdbcType=VARCHAR})"
    })
    int insert(Merchant record);

    @InsertProvider(type=MerchantSqlProvider.class, method="insertSelective")
    int insertSelective(Merchant record);

    @Select({
        "select",
        "id, name, contacts, phone, data_time, pay_type, business_abbreviation, shop_type, ",
        "address, service_phone, weixin_appid, responsible_person, contact, email, cardholder, ",
        "cash_bank, bank_number, card_picture",
        "from st_merchant",
        "where id = #{id,jdbcType=INTEGER}",
          "and name = #{name,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="contacts", property="contacts", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="data_time", property="data_time", jdbcType=JdbcType.DATE),
        @Result(column="pay_type", property="pay_type", jdbcType=JdbcType.TINYINT),
        @Result(column="business_abbreviation", property="business_abbreviation", jdbcType=JdbcType.VARCHAR),
        @Result(column="shop_type", property="shop_type", jdbcType=JdbcType.TINYINT),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="service_phone", property="service_phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="weixin_appid", property="weixin_appid", jdbcType=JdbcType.VARCHAR),
        @Result(column="responsible_person", property="responsible_person", jdbcType=JdbcType.VARCHAR),
        @Result(column="contact", property="contact", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="cardholder", property="cardholder", jdbcType=JdbcType.VARCHAR),
        @Result(column="cash_bank", property="cash_bank", jdbcType=JdbcType.VARCHAR),
        @Result(column="bank_number", property="bank_number", jdbcType=JdbcType.VARCHAR),
        @Result(column="card_picture", property="card_picture", jdbcType=JdbcType.VARCHAR)
    })
    Merchant selectByPrimaryKey(MerchantKey key);

    @UpdateProvider(type=MerchantSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Merchant record);

    @Update({
        "update st_merchant",
        "set contacts = #{contacts,jdbcType=VARCHAR},",
          "phone = #{phone,jdbcType=VARCHAR},",
          "data_time = #{data_time,jdbcType=DATE},",
          "pay_type = #{pay_type,jdbcType=TINYINT},",
          "business_abbreviation = #{business_abbreviation,jdbcType=VARCHAR},",
          "shop_type = #{shop_type,jdbcType=TINYINT},",
          "address = #{address,jdbcType=VARCHAR},",
          "service_phone = #{service_phone,jdbcType=VARCHAR},",
          "weixin_appid = #{weixin_appid,jdbcType=VARCHAR},",
          "responsible_person = #{responsible_person,jdbcType=VARCHAR},",
          "contact = #{contact,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "cardholder = #{cardholder,jdbcType=VARCHAR},",
          "cash_bank = #{cash_bank,jdbcType=VARCHAR},",
          "bank_number = #{bank_number,jdbcType=VARCHAR},",
          "card_picture = #{card_picture,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}",
          "and name = #{name,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Merchant record);
}